import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.adc.quicktools.ObjectUtil;
import com.adc.quicktools.StringUtil;
import com.adc.quicktools.constants.ConstantDefine;
import com.adc.quicktools.file.FileControl;
import com.adc.quicktools.net.UpOrDownControl;
import com.adc.quicktools.process.ExecDaemonThread;
import com.adc.quicktools.process.ProcessControl;


/**
 * @TypeName: Test
 * @Package  
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author shen  shenqiao2012@163.com 
 * @date 2012-6-4 上午11:24:30 
 */
public class TestOther {
	public int test1() { 
		String cmd="ping baidu.com";
		Process process=null;
		try {
			process = Runtime.getRuntime().exec(cmd);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ProcessControl pc=new ProcessControl(true);  //  设定最大等待时间
		int out=pc.executeCommand(process);  // -1 是执行失败
		return out;
	}
	
	public int test2() {
		int out=-1;
		String cmd="ftp 10.10.31.160";  
		String[] evrn={"",""};  //  环境变量
		String dir=null;   //  指定的执行路径
		String outFile=null;  //  指定的日志文件输出全路径
		ExecDaemonThread thread=new ExecDaemonThread(cmd, evrn, dir, outFile);
		thread.start();
		try {
			while (true) { // 一定等到守护线程返回状态值，
				if (thread.getStatus() == 0) {  // 守护线程中的finally会确保 status=0，即不管子进程是否正常结束，都强制返回
					out=thread.getResultvalue();
					break;
				}
				Thread.sleep(50L);
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return out;
	}
	
	public int testHttp() {
		String url="http://10.22.0.116:9999/dcmPic/product/DSTR/MTEM/PDAY/2012/CMDP_CMD_DSTR_DCM_MTEM_AGLB_L88_PB_20120303000000_PDAY_1.PNG";
		String localPath="E:\\TempTest\\testhttp\\"+FileControl.getCurrentTimeString(null)+"/";
//		localPath=localPath.concat(new File(url).getName());
		localPath=localPath.concat("1.png");
		UpOrDownControl udControl=new UpOrDownControl();
		int  s=udControl.upOrDownByType(ConstantDefine.HTTP_DOWN, null, url, localPath);
		System.out.println(udControl.getExecuteReturnInfo());
		return s;
	}
	
	
	public String testFileScan() {
		String parentDir=new File(FileControl.getAppPath(TestOther.class)).getPath();
		String _needfilename="BracketEnum.java.bak";
		return FileControl.fileScanner(parentDir, _needfilename);
	}
	
	public static void main(String[] args) {
//		System.err.println(new Test().test1());
//		System.out.println(new Test().testFileScan());
//		System.err.println("__________________");
//		testSortStringListByLength();
		System.out.println(new File("E:/TempTest/newCollect/test.txt").isDirectory());
	}
	
	public static void testSortStringListByLength() {
		List<String> aList=new ArrayList<String>();
		for (int i = 0; i < 10; i++) {
			int n=(int) (Math.random()*66);
//			System.out.println("random:"+n);
			String string=getRandomString(n);
			System.out.println(string);
			aList.add(string);
		}
		System.err.println("+++++++++++++++complete prepared data++++++++++++++++");
		List<String> bList=StringUtil.sortByLength(aList);
		for (int i = 0; i < bList.size(); i++) {
			System.out.println(bList.get(i));
		}
	}
	
	// 获取随机字符串
		public static String getRandomString(int length) { // length 字符串长度 
		    StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); 
		    StringBuffer sb = new StringBuffer(); 
		    Random r = new Random(); 
		    int range = buffer.length(); 
		    for (int i = 0; i < length; i ++) { 
		        sb.append(buffer.charAt(r.nextInt(range))); 
		    } 
		    return sb.toString(); 
		}

}
